package top.jnaw.jee.pm.controller;

import com.jfinal.core.Controller;
import com.jfinal.kit.PropKit;
import top.jnaw.jee.utils.Https;
import top.jnaw.jee.utils.Log;
import top.jnaw.jee.utils.Shiros;

public class MainController extends Controller {

  public void index() {
    redirect("/main");
  }

  public void main() {
//    boolean result = Shiros.addUser("admin", "123456");
//    Log.d("add admin: " + result);
//
//    result = Shiros.setPwd("admin", "123456");
//    Log.d("set admin pwd: " + result);

//    renderHtml("Main");
//    render("index.html");
    render("login.html");
  }


  public void login() {
    renderJson(Https.failure("没有权限", ""));
  }

  public void check() {
    String user = getPara("user");
    String pwd = getPara("pwd");

    if (Shiros.login(user, pwd)) {
      redirect(PropKit.get("shiro_redirect_success_url"));
    } else {
      redirect(PropKit.get("shiro_redirect_unauthorized_url"));
    }

    Log.i("is authc: " + Shiros.isAuthc());
  }

}
